﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MVVMOpenChildWindow.Base
{
    public class ActionManager
    {
        static Dictionary<string, Delegate> types = new Dictionary<string, Delegate>();

        public static void Register<T>(Action<T> action, string key)
        {
            if (!types.ContainsKey(key))
                types.Add(key, action);
        }

        public static void Register<T>(Func<T> func, string key)
        {
            if (!types.ContainsKey(key))
                types.Add(key, func);
        }

        public static void Invoke<T>(string key, T arg)
        {
            if (types.ContainsKey(key))
                (types[key] as Action<T>).Invoke(arg);
        }

        public static T InvokWithParametere<T>(string key)
        {
            if (types.ContainsKey(key))
                return (types[key] as Func<T>).Invoke();


            return default(T);
        }
    }
}
